﻿using System;
using System.Linq;
using System.Collections.Generic;

namespace Mvc.XForms.Utilities {
	public static class IEnumerableExtensions {
		public static void ForEach<T>(this IEnumerable<T> items, Action<T, int> action) {
			if (items != null) {
				var list = items is IList<T> ? items as IList<T> : items.ToList();

				for (var i = 0; i < list.Count; i++)
					action(list[i], i);
			}
		}

		public static void ForEach<T>(this IEnumerable<T> items, Action<T> action) {
			if (items != null) {
				foreach (var item in items)
					action(item);
			}
		}
	}
}